package level01;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

//代理的作用是在不修改源码的情况下对与原有的对象进行代理
public class MyHandler implements InvocationHandler {
    //定义成员属性--被代理对象
    private Person person;

    public MyHandler(){}

    public MyHandler(Person person) {
        this.person = person;
    }

    void before(){
        System.out.println("项目设计");
    }

    void after(){
        System.out.println("项目总结");
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object result = method.invoke(person);
        after();
        return result;
    }
}
